
#include "osgi-predefined.h"

#define HTTP_OK             200
#define HTTP_NOT_FOUND      404
#define HTTP_SERVER_ERROR   500

#define HTTP_SUCCEED        0
#define HTTP_BIND_FAILED    -301
#define HTTP_URL_EXIST      -302
#define HTTP_URL_NOTEXIST   -303
#define HTTP_GETGET_FAILED  -304
#define HTTP_GETPOST_FAILED -305
#define HTTP_INVOKE_FAILED  -306

#define SID_HttpService                 "SID_HttpService"
#define IID_HttpService                 "IID_HttpService"

#define SID_TestHttpService  "SID_TestHttpService"
#define IID_TestHttpService  "IID_TestHttpService"

OSGI_NAMESPACE_BEGIN

struct IHttpInvokeMsgHandler
{
public:
    virtual void MKRAPI OnMsgCall(IHttpRequest *req, IHttpService* service) = 0;
};

//HTTP服务类
OSGI_INTERFACE IHttpService : public IService
{

    virtual int MKRAPI RegisterHandler(const char *uri, IHttpInvokeMsgHandler *phandle, const char *description) = 0;

    virtual int MKRAPI UnRegisterHandler(const char* uri) = 0;

    virtual int MKRAPI SendInvokeRes(IHttpRequest *httpReq, void *buf, int len, int resCode) = 0;

    virtual void MKRAPI Destroy() = 0;
};

//HTTP请求解析类
OSGI_INTERFACE IHttpRequest
{
    virtual int MKRAPI GetBody(char **ppBody) = 0;
    virtual int MKRAPI GetMethod(char **ppMethod) = 0;
    virtual int MKRAPI GetRequestURI(char **ppUri) = 0;
    virtual int MKRAPI GetQueryString(char **ppQueryString) = 0;
    virtual int MKRAPI GetRemoteAddr(char **ppRemoteAddr) = 0;
    virtual int MKRAPI GetRemotePort() = 0;

    virtual int MKRAPI GetHeader(const char *key, char **ppVal) = 0;
    virtual int MKRAPI GetParameter(const char *key, char **ppVal) = 0;

    virtual void MKRAPI releaseData(char* data) = 0;
    virtual void MKRAPI Destroy() = 0;
};

OSGI_NAMESPACE_END

